package LeetCode.Simple;


import java.util.Stack;

/*
判断二叉树是否对称
请实现一个函数，用来判断一棵二叉树是不是对称的。如果一棵二叉树和它的镜像一样，那么它是对称的。

例如，二叉树[1,2,2,3,4,4,3] 是对称的。
但是下面这个[1,2,2,null,3,null,3] 则不是镜像对称的:
 */
public class Question010 {
    public boolean isSymmetric(TreeNode root){
        if(root.left.val != root.right.val){
            return false;
        }
        return isSame(root.left, root.right);
    }

    public boolean isSame(TreeNode left, TreeNode right){
        if(left.val != right.val){
            return false;
        }
        return isSame(left.left,right.right) && isSame(left.right, right.left);
    }
}

class TreeNode {
    public int val;
    public TreeNode left;
    public TreeNode right;

    public TreeNode() {
    }

    public TreeNode(int val) {
        this.val = val;
    }

    public TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}



